package com.stmt.analytic.graph.algorithm.lv;

import com.stmt.analytic.graph.algorithm.IdMapping;
import com.stmt.analytic.graph.algorithm.Pair;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;

public class LouvainMain {

    public static void main(String[] args) throws IOException {
        Collection<String> vertices = new ArrayList<>();
        Collection<Pair<String, String>> edges = new ArrayList<>();
        vertices.add("a");
        vertices.add("b");
        vertices.add("c");
        vertices.add("d");
        vertices.add("e");
        vertices.add("f");
        vertices.add("g");
        vertices.add("h");
        vertices.add("i");
        vertices.add("j");
        vertices.add("k");

        edges.add(new Pair<>("a", "b"));
        edges.add(new Pair<>("c", "b"));
        edges.add(new Pair<>("d", "b"));
        edges.add(new Pair<>("e", "b"));
        edges.add(new Pair<>("e", "a"));
        edges.add(new Pair<>("e", "c"));
        edges.add(new Pair<>("f", "e"));
        edges.add(new Pair<>("g", "f"));
        edges.add(new Pair<>("h", "g"));
        edges.add(new Pair<>("h", "i"));
        edges.add(new Pair<>("k", "j"));
        edges.add(new Pair<>("j", "i"));

        IdMapping idMapping = new IdMapping(vertices.size());
        vertices.forEach(oid -> {
            idMapping.add(oid);
        });
        Louvain louvain = Louvain.builder().withVertices(vertices)
                .withEdges(edges)
                .build();
        LouvainCommunities communities = louvain.compute();
        Map<Integer, LouvainCommunities.LouvainCommunity> communitiesAll = communities.getAll();
        communitiesAll.forEach((k,v)->{
            System.out.println(k + ":" + v);
        });
    }
}
